new Vue({
    el: '#app',
    data() {
        return {
            form: {
                Data: '',
                Type: '',
                page: 1,			//页数
                limit: 10,			//每页数据条数
            },
            screen: '',//筛选
            type: [],
            tableData: [],	//表格数据
        }
    },
    mounted() {
        this.getList();//前端分页
    },
    methods: {
        onSerach() {			//查询方法
            this.screen = this.form.Data;
            this.form.page = 1;
        },
        Add() {
            window.location.href = './add.html'
        },
        handleSizeChange(val) {
            this.form.page = 1;
            this.form.limit = val;
        },
        handleCurrentChange(val) {
            this.form.page = val;
        },
        getList() {//换页方法
            const that = this
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryAllTableName`,
                type: 'GET',
                success: function (Data) {
                    that.tableData = [];
                    if (Data.length > 0) {
                        Data.forEach(item => {
                            item.loading = false;
                            item.Children = {
                                base_table_detail: []
                            }
                        });
                        that.tableData = Data;
                    }
                },
                complete: function (XMLHttpRequest) {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            });
        },
        Edit(TABLE_NAME) {
            sessionStorage.setItem("TABLE_NAME", TABLE_NAME)
            window.location.href = './edit.html?TABLE_NAME=' + TABLE_NAME
        },
        expandChange(row) {
            const that = this;
            $.ajax({
                headers: requestHeaders(),
                url: `${BASE_URL2}/generalBusiness/generalQueryAllColumnByTableName`,
                type: 'GET',
                data: { Data: row.TABLE_NAME },
                success: function (data) {
                    if (data.length > 0) {
                        row.Children.base_table_detail = data;
                    }
                },
                complete: function (XMLHttpRequest) {
                    that.loading = false
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json"
            })
        },
        Remove(row) {
            const that = this
            this.$prompt('警告！此操作将删除该表,可能会引起错误, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                inputPlaceholder: "请输入'确认删除'",
                inputPattern:/^确认删除$/,
                inputErrorMessage: "请输入'确认删除'",
            }).then(() => {
                row.loading = true;
                let Data = "DROP TABLE IF EXISTS " + row.TABLE_NAME + ";"
                $.ajax({
                    headers: requestHeaders(),
                    url: `${BASE_URL2}/generalBusiness/generalDataTableOperation`,
                    type: 'POST',
                    data: { Data },
                    success: function (res) {
                        console.log(res);
                        if (res.Status == 'success') {
                            that.getList(that.form);
                            that.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        }
                    },
                    complete: function (XMLHttpRequest) {
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json"
                })
            }).catch(() => { });
        }

    },
})